package au.org.nh.form;

import au.org.nh.dao.PatientInfo;
import au.org.nh.dao.PatientInfoDAO;
import au.org.nh.dao.hsqldb.impl.HSQLDBPatientInfoDAOImpl;
import au.org.nh.dao.mongo.impl.DBException;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * @author amith.nambiar
 * 
 */
public class SavePatientInfoAction {
	private PatientInfo info;
	/* TODO : Inject the dependency using IoC Container */
	private final PatientInfoDAO saveDAO = new HSQLDBPatientInfoDAOImpl();

	public String execute() {
		try {
			final Gson gson = new GsonBuilder().setPrettyPrinting().create();
			System.out.println("JSON representation is :" + gson.toJson(info));
			saveDAO.save(info);
		} catch (final DBException e) {
			e.printStackTrace();
		}
		return "view";
	}

	public void setInfo(final PatientInfo info) {
		this.info = info;
	}

	public PatientInfo getInfo() {
		return info;
	}

}
